#include "mbappwig.h"
#include "ui_mbappwig.h"

MbappWig::MbappWig(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MbappWig)
{
    ui->setupUi(this);
    ui->pushButton_temperature->setIcon(QIcon(":/ewoshiwendu.png"));
    ui->pushButton_temperature->setIconSize(QSize(100,100));
    ui->pushButton_humidity->setIcon(QIcon(":/ewoshishidu.png"));
    ui->pushButton_humidity->setIconSize(QSize(100,100));
    ui->pushButton_swith->setIcon(QIcon(":/new/prefix1/newair_cond.png"));
    ui->pushButton_swith->setIconSize(QSize(100,100));
    ui->pushButton_temp->setIcon(QIcon(":/new/prefix1/newthermostat.png"));
    ui->pushButton_temp->setIconSize(QSize(100,100));
    ui->pushButton_light->setIcon(QIcon(":/new/prefix1/newlight.png"));
    ui->pushButton_light->setIconSize(QSize(100,100));

    connect(ui->pushButton_swith,SIGNAL(clicked()),this,SLOT(switchkz()));
    connect(ui->pushButton_light,SIGNAL(clicked()),this,SLOT(lightkz()));
    connect(ui->pushButton_temp,SIGNAL(clicked()),this,SLOT(temkz()));
    connect(ui->pushButton_sx,SIGNAL(clicked()),this,SLOT(mbasx()));

}

MbappWig::~MbappWig()
{
    delete ui;
}

void MbappWig::modbustemperaturedata(QString str)
{
    ui->label->setText(str);
}

void MbappWig::modbushumiditydata(QString str)
{
    ui->label_2->setText(str);
}

void MbappWig::switchkz()
{
    if(ui->label_3->text()=="off")
    {
        int wskt=0;
        ui->label_3->setText("on");
        emit mbaswith(wskt);


    }
    else if(ui->label_3->text()=="on")
    {
        int wskt=1;
        ui->label_3->setText("off");
        emit mbaswith(wskt);
    }
}
void MbappWig::lightkz()
{
    if(ui->label_5->text()=="off")
    {
        int wsdp=0;
        ui->label_5->setText("on");
        emit mbalight(wsdp);

    }
    else if(ui->label_5->text()=="on")
    {
        int wsdp=1;
        ui->label_5->setText("off");
        emit mbalight(wsdp);
    }
}

void MbappWig::temkz()
{
    if(ui->label_3->text()=="off")
    {
        QMessageBox::information(this,"information","Turn on the air conditioner first");
    }
    else if(ui->label_3->text()=="on")
    {
        QString wendu=ui->lineEdit->text();
        emit mbatem(wendu);
    }
}
void MbappWig::mbasx()
{
    int index=1;
    emit shuaxin(index);
}
